package com.py.credit.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.py.credit.dao.AppSelectDao;
import com.py.credit.service.AppSelectService;
@Service
public class AppSelectServiceImpl implements AppSelectService{
	@Autowired
	private  AppSelectDao appSelectDao;

	@Override
	public List<Map<String, Object>> select(String userid) {
		List<Map<String, Object>> list=appSelectDao.selectGZ(userid);
		String qymc="";
		String tyshxydm="";
		List<Map<String, Object>> resultlist=new ArrayList<Map<String, Object>>();
		if(!CollectionUtils.isEmpty(list)){
			for(int i=0;i<list.size();i++){
				Map<String, Object> map=new HashMap<String, Object>(4);
				qymc=String.valueOf(list.get(i).get("qymc"));
				tyshxydm=String.valueOf(list.get(i).get("tyshxydm"));
				map.put("tybm", String.valueOf(list.get(i).get("tybm")));
				map.put("qymc", qymc);
				map.put("tyshxydm", tyshxydm);
				map.put("cf", appSelectDao.selectCf(qymc, tyshxydm));
				map.put("hei", appSelectDao.selectHEI(qymc, tyshxydm));
				map.put("hong", appSelectDao.selectHONG(qymc, tyshxydm));
				map.put("xk", appSelectDao.selectXk(qymc, tyshxydm));
				resultlist.add(map);
			}
			
		}
		
		return resultlist;
	}

	@Override
	public List<Map<String, Object>> selectYsHs(String type,String name,String pageNo, String pageSize) {
		if("y".equals(type)){
			return appSelectDao.selectYS(name, pageNo, pageSize);
		}
		if("h".equals(type)){
			return appSelectDao.selectHS(name, pageNo, pageSize);
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> selectJYYCML(String name,String pageNo, String pageSize) {
		return appSelectDao.selectJYYCML(name, pageNo, pageSize);
	}

	@Override
	public Map<String,Object> selectHong() {
		Map<String,Object> map=new HashMap<String,Object>();
		//法人红榜
		map.put("fr", appSelectDao.selectHongBang("t_1000000010005_JgddEske8s"));
		//自然人红榜
		map.put("zrr", appSelectDao.selectHongBang("t_1000010010006_5qTzTGI6gL"));
		return map;
	}

	@Override
	public Map<String,Object> selectHei() {
		Map<String,Object> map=new HashMap<String,Object>();
		//法人黑榜
		map.put("fr", appSelectDao.selectHeiBang("t_1000000010007_u6tnVOcB9I"));
		//自然人黑榜
		map.put("zrr", appSelectDao.selectHeiBang("t_1000010010008_VU2pjsxdhk"));
		return map;
	}
	
	@Transactional
	@Override
	public void deleteGZ(String userid, String tybm) {
		appSelectDao.deleteGZ(userid, tybm);
	}
	
	@Transactional
	@Override
	public void addGZ(String userid, String tybm, String qymc, String tyshxydm) {
		appSelectDao.addGZ(userid, tybm, qymc, tyshxydm);
	}

	@Override
	public List<Map<String, Object>> selectGZ(String userid) {
		return appSelectDao.selectGZ(userid);
	}

	@Override
	public List<Map<String, Object>> selectQYGZ(String qymc, String pageNo, String pageSize, String userid) {
		return appSelectDao.selectQYGZ(qymc, pageNo, pageSize, userid);
	}


}
